<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline" >
        <a-row :gutter="48">
          <a-col :md="8" :sm="24">
            <a-form-item label="定时器名称">
              <a-input v-model="searchParam.quartzName" placeholder=""/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item label="状态">
              <a-select  style="width: 100%" v-model="searchParam.quartzState">
                <a-select-option :value="0">启动</a-select-option>
                <a-select-option :value="1">暂停</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
          </template>
          <a-col :md="!advanced && 8 || 24" :sm="24">
            <span class="table-page-search-submitButtons"
                  :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
              <a-button type="primary" @click="search">查询</a-button>
              <a-button style="margin-left: 8px" @click="reset">重置</a-button>
<!--              <a @click="toggleAdvanced" style="margin-left: 8px">-->
<!--                {{ advanced ? '收起' : '展开' }}-->
<!--                <a-icon :type="advanced ? 'up' : 'down'"/>-->
<!--              </a>-->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <div class="table-operator">
      <a-button type="primary" icon="plus" @click="$refs.save.add()">新建</a-button>
      <a-dropdown  v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay"  @click="handleMenuClick">
          <a-menu-item key="delete">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">
          批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <a-table
      :rowKey=" (record => record.id)"
      :dataSource="tableData"
      :pagination="pagination"
      :loading="loading"
      :rowSelection="rowSelection"
    >
      <a-table-column title="定时器名称" dataIndex="quartzName" key="quartzName"/>
      <a-table-column title="cron表达式" dataIndex="cron" key="cron"/>
      <a-table-column title="参数" dataIndex="param" key="param"/>
      <a-table-column title="描述" dataIndex="quartzDesc" key="quartzDesc"/>
      <a-table-column title="状态" dataIndex="quartzState" key="quartzState">
        <template slot-scope="quartzState">
          <a-tag color="#108ee9" v-if="quartzState===0">启动</a-tag>
          <a-tag color="#f50" v-if="quartzState===1">暂停</a-tag>
        </template>
      </a-table-column>
      <a-table-column title="创建时间" dataIndex="createdTime" key="createdTime"/>
      <a-table-column title="操作">
        <template slot-scope="record">
        <span>
           <a href="javascript:;" @click="updateState(record)">{{record.quartzState===0?'停止':'启动'}}</a>
           <a-divider type="vertical"/>
          <a href="javascript:;" @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical"/>
            <a-popconfirm title="确定删除吗？" @confirm="handleDelete(record)">
                 <a-icon slot="icon" type="question-circle-o" style="color: red"/>
                <a href="javascript:;">删除</a>
             </a-popconfirm>
        </span>
        </template>
      </a-table-column>
    </a-table>

    <save ref="save" @refresh="refresh"></save>
  </a-card>
</template>


<script>
  import save from './save/save'
  import curdMixins from '../../../common/mixins/curdMixins'
  import { selectPage,deleteByIds,updateQuartzState,deleteById } from '../../../api/base/quartz'

  export default {
    name: 'quartz',
    mixins: [curdMixins],
    components: {
      save
    },
    data(){
      return{
         multiOperator:[
           {
             key: "delete",
             method: deleteByIds,
             msg:"批量删除成功",
             tip:"确定批量删除吗？"
           }
         ]
      }
    },
    methods: {
      getList(param) {
        return selectPage(param)
      },
      delete(param){
        return deleteById(param)
      },
      updateState(data){
        data=JSON.parse(JSON.stringify(data));
        if(data.quartzState){
          data.quartzState=0;
        }else {
          data.quartzState=1;
        }
        updateQuartzState(data).then(res=>{
          if(res.status===0){
            this.$message.success("修改状态成功");
            this.refresh();
          }else {
            this.$message.error(res.msg);
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>